import { useLocation } from 'react-router-dom';
import { useAppSelector } from '@/redux';
import { select_menu } from '@/redux/slice/user';

/**
 * 控制导航菜单是否显示
 * @returns 返回布尔值
 */
const useIsShowMenu = () => {
  const location = useLocation();
  const menus = useAppSelector(select_menu);

  const key: any = location.pathname.split('/')[1];
  //如果没有key,什么都没有
  if (!key || !menus.length) {
    return false;
  }

  const menu: any = menus.find((item: any) => {
    return item.key === key;
  });

  if (menu?.hasMenu) {
    return true;
  } else {
    return false;
  }
};

export default useIsShowMenu;
